import java.util.Random;
import java.util.Scanner;
public class opreation {
    //获取一个数二进制序列中所有的偶数位和奇数位， 分别输出二进制序列
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        System.out.println("请输入一个数字");
        int n = scan.nextInt();
        System.out.println("偶数位");
        for (int i =30; i>=0; i=i-2) {
            System.out.print(((n>>i)&1)+" ");
        }
        System.out.println("\n" + "奇数位");
        for (int i =31; i >=1; i = i -2) {
            System.out.print(((n>>i)&1)+" ");
        }
    }
//编写代码模拟三次密码输入的场景。 最多能输入三次密码，密码正确，提示“登录成功”,密码错误，
// 可以重新输 入，最多输入三次。三次均错，则提示退出程序
public static void main12(String[] args) {
    int n = 3;
    while (n > 0) {
        String password = "123456";
        System.out.println("请输入密码");
        Scanner scan = new Scanner(System.in);
        String arr = scan.nextLine();
        if (arr.equals(password)) {
            System.out.println("登录成功");
            break;
        } else {
            System.out.println("密码错误,剩余" + (n - 1) + "次");
            n--;
        }
    }
    if (n == 0) {
        System.out.println("输入错误三次，退出程序");
    }
}
    //输出一个整数的每一位，如：123的每一位是3，2，1
    public static void main11(String[] args) {
        Scanner scan=new Scanner(System.in);
        System.out.println("请输入一个数");
        int n= scan.nextInt();
        while(n!=0){
            int b=n%10;
            System.out.print(b+"\t");
            n=n/10;
        }
    }
//输出n*n的乘法口诀表，n由用户输入。
    public static void main10(String[] args) {
        Scanner scan = new Scanner(System.in);
        System.out.println("请输入一个数");
        int n = scan.nextInt();
        for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= i; j++) {
                int mul = i * j;
                System.out.print(i + "*" + j + "=" + mul + "\t");
            }
            System.out.println();
        }
    }
    //针对每行输入，输出用“*”组成的X形图案。
    public static void main9(String[] args) {
        Scanner scan=new Scanner(System.in);
        System.out.println("请输入一个数字");
        while(scan.hasNextInt()){
            int tmp=scan.nextInt();
            for (int i = 0; i <tmp ; i++) {
                for (int j = 0; j <tmp; j++) {
                    if(i==j){
                        System.out.print("*");
                    }
                    else if(i+j==tmp-1){
                        System.out.print("*");
                    }else{
                        System.out.print(" ");
                    }
                }
                System.out.println();
            }
        }
    }
    //求出0～n之间的所有“水仙花数”并输出。(“水仙花数”是指一个三位数，其各位数字的立方和确好等于该数本 身，
    // 如；153＝1^3＋5^3＋3^3，则153是一个“水仙花数“。）
    public static void main8(String[] args) {
        Scanner scan = new Scanner(System.in);
        System.out.println("请输入n");
        int n = scan.nextInt();
        for (int i = 0; i <= n; i++) {
            int count=0;
            int tmp=i;
            while( tmp!=0) {
                tmp = tmp / 10;
                count++;
            }
            tmp = i;
            int sum = 0;
            while (tmp!= 0) {
                sum += Math.pow(tmp%10,count);
                tmp = tmp / 10;
            }
            if (sum == i) {
                System.out.println("水仙花数为" + i);
            }
        }
    }
    //计算1/1-1/2+1/3-1/4+1/5 …… + 1/99 - 1/100 的值 。
    public static void main7(String[] args) {
        int i=0;
        double sum=0.0;
        for (i = 1; i <=100 ; i++) {
            if(i%2!=0){
                sum=sum+1.0/i;
            }else{
                sum=sum-1.0/i;
            }
        }
        System.out.println("和为"+sum);
    }
    //求一个整数，在内存当中存储时，二进制1的个数。
    public static void main6(String[] args) {
        Scanner scan = new Scanner(System.in);
        System.out.println("请输入一个数字");
        int num = scan.nextInt();
        int count = 0;
        while (num != 0) {
            if ((num & 1) == 1) {
                count++;
            }
            num = num >> 1;
        }
        System.out.println("有" + count + "个1");

    }
    public static void main5(String[] args) {

        Random random=new Random();
        Scanner scan=new Scanner(System.in);
        int age=random.nextInt(100);
        while(true) {
            System.out.print("请输入数字  ");
            int num= scan.nextInt();
            if(num<age){
                System.out.println("猜小了!");
            }else if(num>age){
                System.out.println("猜大了!");
            }else{
                System.out.println("猜对了!");
                break;
            }
        }
    }

    public static void main4(String[] args) {
        int i = 1;
        for(i=1;i<=100;i++){
            if ((i % 3 == 0) && (i % 5 == 0)) {
                System.out.println(i);
                continue;
            }

        }
    }
    public static void main3(String[] args) {
        int i = 0;
        int j= 0;
        int mul = 1;
        int sum = 0;
        for (i = 1; i <= 5; i++) {
            mul=1;
            j=0;
            for (j = 1; j <= i; j++) {
                mul = mul * j;
            }
            sum = sum + mul;
        }
        System.out.println("阶乘和是" + sum);
    }
    public static void main1(String[] args) {
        int i = 0;
        int sum = 0;//总和
        int asum = 0;//偶数和
        int bsum = 0;//奇数和
        for (i = 1; i <= 100; i++) {
            sum = sum + i;
            if (i % 2 == 0) {
                asum = asum + i;
            }
        }
        System.out.println("总和为" + sum);
        System.out.println("偶数和" + asum);
        System.out.println("奇数和" + (sum - asum));
    }
}
